package com.ruoyi.project.module.connector.service;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.datascope.DataScopeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.module.connector.mapper.ConnectorMapper;
import com.ruoyi.project.module.connector.domain.Connector;
import com.ruoyi.project.module.connector.service.IConnectorService;
import com.ruoyi.common.support.Convert;

/**
 * 接口模块 服务层实现
 * 
 * @author ruoyi
 * @date 2018-10-02
 */
@Service
public class ConnectorServiceImpl implements IConnectorService 
{
	@Autowired
	private ConnectorMapper connectorMapper;

	/**
     * 查询接口模块信息
     * 
     * @param apiConnectorId 接口模块ID
     * @return 接口模块信息
     */
    @Override
	public Connector selectConnectorById(Integer apiConnectorId)
	{
	    return connectorMapper.selectConnectorById(apiConnectorId);
	}
	
	/**
     * 查询接口模块列表
     * 
     * @param connector 接口模块信息
     * @return 接口模块集合
     */
	@Override
	public List<Connector> selectConnectorList(Connector connector)
	{
		// 生成数据权限过滤条件
		connector.getParams().put("dataScope", DataScopeUtils.dataScopeFilter("connector"));
	    return connectorMapper.selectConnectorList(connector);
	}
	
    /**
     * 新增接口模块
     * 
     * @param connector 接口模块信息
     * @return 结果
     */
	@Override
	public int insertConnector(Connector connector)
	{
		String userName = ShiroUtils.getUser().getLoginName();
		connector.setCreateBy(userName);
		connector.setCreateTime(new Date());
		connector.setUpdateBy(userName);
		connector.setUpdateTime(new Date());
	    return connectorMapper.insertConnector(connector);
	}
	
	/**
     * 修改接口模块
     * 
     * @param connector 接口模块信息
     * @return 结果
     */
	@Override
	public int updateConnector(Connector connector)
	{
		String userName = ShiroUtils.getUser().getLoginName();
		connector.setCreateBy(null);
		connector.setCreateTime(null);
		connector.setUpdateBy(userName);
		connector.setUpdateTime(new Date());
	    return connectorMapper.updateConnector(connector);
	}

	/**
     * 删除接口模块对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteConnectorByIds(String ids)
	{
		return connectorMapper.deleteConnectorByIds(Convert.toStrArray(ids));
	}
	
}
